package com.spark.concurrency.thread.method;

/**
 * 使用 System.exit(0) 可以让整个程序退出；
 * 要中断单个线程，可配合 interrupt() 对线程进行“中断”
 */
public class InterruptTest {
    public static void main(String[] args) throws InterruptedException {
        Thread interruptThread = new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < Integer.MAX_VALUE; i++) {
                    System.out.println(i);
                    if (this.isInterrupted()) {
                        break;
                    }
                }
            }
        };
        interruptThread.start();
        Thread.sleep(10);
        interruptThread.interrupt();
    }
}
